package com.splic.product.service.impl;

import java.util.Date;
import java.util.List;
import com.splic.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.splic.product.mapper.ChannelMapper;
import com.splic.product.domain.Channel;
import com.splic.product.service.ChannelService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 渠道Service业务层处理
 * 
 * @author singe
 * @date 2022-01-04
 */
@Service
public class ChannelServiceImpl implements ChannelService
{
    @Autowired
    private ChannelMapper channelMapper;

    /**
     * 查询渠道
     * 
     * @param id 渠道主键
     * @return 渠道
     */
    @Override
    public Channel selectChannelById(Long id)
    {
        return channelMapper.selectChannelById(id);
    }

    /**
     * 查询渠道列表
     * 
     * @param channel 渠道
     * @return 渠道
     */
    @Override
    public List<Channel> selectPageList(Channel channel)
    {
        return channelMapper.selectChannelList(channel);
    }

    /**
     * 查询渠道列表
     *
     * @param channel 渠道
     * @return 渠道
     */
    @Override
    public List<Channel> selectChannelList(Channel channel)
    {
        return channelMapper.selectChannelList(channel);
    }

    /**
     * 新增渠道
     * 
     * @param channel 渠道
     * @return 结果
     */
    @Override
    public int insert(Channel channel)
    {
        channel.setCreateTime(DateUtils.getNowDate());
        return channelMapper.insert(channel);
    }

    /**
     * 修改渠道
     * 
     * @param channel 渠道
     * @return 结果
     */
    @Override
    public int update(Channel channel)
    {
        channel.setUpdateTime(DateUtils.getNowDate());
        return channelMapper.update(channel);
    }


    /**
     * 删除渠道信息
     * 
     * @param id 渠道主键
     * @return 结果
     */
    @Override
    public int deleteById(Long id)
    {
        return channelMapper.deleteById(id);
    }
    /**
     * 修改渠道
     *
     * @param channel 渠道信息
     * @return 结果
     */
    @Override
    @Transactional
    public int saveOrUpdate(Channel channel)
    {
        if(channel.getId() != null){
            channel.setUpdateTime(new Date());
            return channelMapper.update(channel);
        }else{
            channel.setCreateTime(new Date());
            return channelMapper.insert(channel);
        }
    }
}
